home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_apache2.idb / usr / freeware / apache2 / include / apr_mmap.h.z / apr_mmap.h
C/C++ Source or Header  |  2002-07-08  |  7KB  |  200 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  */
  54.  
  55. #ifndef APR_MMAP_H
  56. #define APR_MMAP_H
  57.  
  58. #include "apr.h"
  59. #include "apr_pools.h"
  60. #include "apr_errno.h"
  61. #include "apr_file_io.h"        /* for apr_file_t */
  62.  
  63. #ifdef BEOS
  64. #include <kernel/OS.h>
  65. #endif
  66.  
  67. #ifdef __cplusplus
  68. extern "C" {
  69. #endif /* __cplusplus */
  70. /**
  71.  * @file apr_mmap.h
  72.  * @brief APR MMAP routines
  73.  */
  74. /**
  75.  * @defgroup APR_MMAP MMAP (Memory Map) Routines
  76.  * @ingroup APR
  77.  * @{
  78.  */
  79.  
  80. #define APR_MMAP_READ    1
  81. #define APR_MMAP_WRITE   2
  82.  
  83. typedef struct apr_mmap_t            apr_mmap_t;
  84. /**
  85.  * @remark
  86.  * As far as I can tell the only really sane way to store an MMAP is as a
  87.  * void * and a length.  BeOS requires this area_id, but that's just a little
  88.  * something extra.  I am exposing this type, because it doesn't make much
  89.  * sense to keep it private, and opening it up makes some stuff easier in
  90.  * Apache.
  91.  */
  92. /** The MMAP structure */
  93. struct apr_mmap_t {
  94.     /** The pool the mmap structure was allocated out of. */
  95.     apr_pool_t *cntxt;
  96. #ifdef BEOS
  97.     /** An area ID.  Only valid on BeOS */
  98.     area_id area;
  99. #endif
  100. #ifdef WIN32
  101.     /** The handle of the file mapping */
  102.     HANDLE mhandle;
  103.     /** The start of the real memory page area (mapped view) */
  104.     void *mv;
  105.     /** The physical start, size and offset */
  106.     apr_off_t  pstart;
  107.     apr_size_t psize;
  108.     apr_off_t  poffset;
  109. #endif
  110.     /** The start of the memory mapped area */
  111.     void *mm;
  112.     /** The amount of data in the mmap */
  113.     apr_size_t size;
  114.     /** Whether this object is reponsible for doing the munmap */
  115.     int is_owner;
  116. };
  117.  
  118. #if APR_HAS_MMAP || defined(DOXYGEN)
  119.  
  120. /* Files have to be at least this big before they're mmap()d.  This is to deal
  121.  * with systems where the expense of doing an mmap() and an munmap() outweighs
  122.  * the benefit for small files.  It shouldn't be set lower than 1.
  123.  */
  124. #ifdef MMAP_THRESHOLD
  125. #  define APR_MMAP_THRESHOLD              MMAP_THRESHOLD
  126. #else
  127. #  ifdef SUNOS4
  128. #    define APR_MMAP_THRESHOLD            (8*1024)
  129. #  else
  130. #    define APR_MMAP_THRESHOLD            1
  131. #  endif /* SUNOS4 */
  132. #endif /* MMAP_THRESHOLD */
  133.  
  134. #ifdef MMAP_LIMIT
  135. #  define APR_MMAP_LIMIT                  MMAP_LIMIT
  136. #else
  137. #  define APR_MMAP_LIMIT                  (4*1024*1024)
  138. #endif /* MMAP_LIMIT */
  139.  
  140. #define APR_MMAP_CANDIDATE(filelength) \
  141.     ((filelength >= APR_MMAP_THRESHOLD) && (filelength < APR_MMAP_LIMIT))
  142.  
  143. /*   Function definitions */
  144.  
  145. /** 
  146.  * Create a new mmap'ed file out of an existing APR file.
  147.  * @param newmmap The newly created mmap'ed file.
  148.  * @param file The file turn into an mmap.
  149.  * @param offset The offset into the file to start the data pointer at.
  150.  * @param size The size of the file
  151.  * @param flag bit-wise or of:
  152.  * <PRE>
  153.  *          APR_MMAP_READ       MMap opened for reading
  154.  *          APR_MMAP_WRITE      MMap opened for writing
  155.  * </PRE>
  156.  * @param cntxt The pool to use when creating the mmap.
  157.  */
  158. APR_DECLARE(apr_status_t) apr_mmap_create(apr_mmap_t **newmmap, 
  159.                                           apr_file_t *file, apr_off_t offset,
  160.                                           apr_size_t size, apr_int32_t flag,
  161.                                           apr_pool_t *cntxt);
  162.  
  163. /**
  164.  * Duplicate the specified MMAP.
  165.  * @param new_mmap The structure to duplicate into. 
  166.  * @param old_mmap The file to duplicate.
  167.  * @param p The pool to use for the new file.
  168.  * @param transfer_ownership  Whether responsibility for destroying
  169.  *  the memory-mapped segment is transferred from old_mmap to new_mmap
  170.  */         
  171. APR_DECLARE(apr_status_t) apr_mmap_dup(apr_mmap_t **new_mmap,
  172.                                        apr_mmap_t *old_mmap,
  173.                                        apr_pool_t *p,
  174.                                        int transfer_ownership);
  175.  
  176. /**
  177.  * Remove a mmap'ed.
  178.  * @param mmap The mmap'ed file.
  179.  */
  180. APR_DECLARE(apr_status_t) apr_mmap_delete(apr_mmap_t *mm);
  181.  
  182. /** 
  183.  * Move the pointer into the mmap'ed file to the specified offset.
  184.  * @param addr The pointer to the offset specified.
  185.  * @param mmap The mmap'ed file.
  186.  * @param offset The offset to move to.
  187.  */
  188. APR_DECLARE(apr_status_t) apr_mmap_offset(void **addr, apr_mmap_t *mm, 
  189.                                           apr_off_t offset);
  190.  
  191. #endif /* APR_HAS_MMAP */
  192. /** @} */
  193. #ifdef __cplusplus
  194. }
  195. #endif
  196.  
  197. #endif  /* ! APR_MMAP_H */
  198.  
  199.  
  200.